package com.hksj.crsm.controller;

import com.hksj.base.query.AlarmQuery;
import com.hksj.base.query.BaseRecordQuery;
import com.hksj.base.query.ChartQuery;
import com.hksj.common.core.model.Rest;
import com.hksj.crsm.query.CrsmDailyAlarmQuery;
import com.hksj.crsm.query.CrsmSpecialityQuery;
import com.hksj.crsm.service.CrsmService;
import com.hksj.crsm.vo.BarChartVO;
import com.hksj.crsm.vo.CrsmCurrentAlarmInfoVO;
import com.hksj.crsm.vo.CrsmDailyAlarmNumVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "机房安全-接口")
@RequestMapping("/api/crsm")
@RestController
public class CrsmController {
    @Autowired
    private CrsmService crsmService;

    @ApiOperation("设备列表-查询设备各属性柱状图")
    @PostMapping("/listBarChartData")
    public Rest<List<BarChartVO>> listBarChartData(@RequestBody @Validated ChartQuery query){
        List<BarChartVO> list = crsmService.listBarChartData(query);
        return Rest.ok(list);
    }

    @ApiOperation("大屏-当前报警设备情况")
    @PostMapping("/getCurrentAlarmInfo")
    public Rest<CrsmCurrentAlarmInfoVO> getCurrentAlarmInfo(@RequestBody CrsmSpecialityQuery query){
        CrsmCurrentAlarmInfoVO res = crsmService.getCurrentAlarmInfo(query);
        return Rest.ok(res);
    }

    @ApiOperation("大屏-最近7天报警次数")
    @PostMapping("/listDailyAlarmNum")
    public Rest<List<CrsmDailyAlarmNumVO>> listDailyAlarmNum(@RequestBody CrsmDailyAlarmQuery query){
        List<CrsmDailyAlarmNumVO> list = crsmService.listDailyAlarmNum(query);
        return Rest.ok(list);
    }

    @ApiOperation("报警记录-导出")
    @PostMapping("/exportAlarm")
    public void exportAlarm(@RequestBody AlarmQuery query, HttpServletResponse response){
        crsmService.exportAlarm(query,response);
    }

//    @ApiOperation("高温-导出")
//    @PostMapping("/exportTemperature")
//    public void exportTemperature(){
//
//    }

    @ApiOperation("漏水-导出")
    @PostMapping("/exportLeakage")
    public void exportLeakage(@RequestBody @Validated BaseRecordQuery query ,HttpServletResponse response){
        crsmService.exportLeakage(query,response);
    }
}
